from flask import Blueprint, request, render_template, g
from ..core import data_flow_diag
from . import get_data, handle_error, params_check
from werkzeug.datastructures import FileStorage

code_blueprint = Blueprint('code_blueprint', __name__, url_prefix='/code')


@code_blueprint.before_request
@handle_error
def before_request():
    get_data()


@code_blueprint.route('/loc', methods=['POST'])
def handle():
    if request.method == 'POST':
        print("aaa", request.files.get('file').__class__)
        a: FileStorage = request.files.get('file')
        b = a.stream.readlines()
        return code.getLCOM()
    else:
        return None

# 测试用
@code_blueprint.route('/hello')
def hello():
    return {'code': 200, 'data': "success! :)"}
